<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>资金申请</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">资金申请管理</div>
		</div>
	</div>
	<div class="new-form" >
		<div>
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 80px;">项目:</td>
						<td id="width1">
							<input style="width: 100%;" id="projectitem" name="projectitem" class="easyui-combobox"
								editable="false"
								data-options="
							    valueField: 'id',
							    textField: 'name',
							    url: '../projectitemlist.do?status=2',
							    onSelect: function(rec){
								    if(rec.projectitemchilds.length>0){
										document.getElementById('tr').style.display = '';
										//document.getElementById('tr2').style.display = '';
										var url = '../projectitemchildlist?status=2&&projectitemid=' + rec.id;
										$('#projectitemchild').combobox('reload', url);
								    }else{
										document.getElementById('tr').style.display = 'none';
										//document.getElementById('tr2').style.display = 'none';
							    	}
							    },panelHeight: 'auto'">
						</td>
					</tr>
					<tr id="tr" style="display: none;">
						<td>子项目:</td>
						<td>
							<input style="width: 80px;" id="projectitemchild" name="projectitemchild" class="easyui-combobox"
								editable="false"
								data-options="
							    valueField: 'id',
							    textField: 'name',
							    onSelect: function(rec){
									
							    },panelHeight: 'auto'">
						</td>
					</tr>
					<tr>
						<td style="width: 80px;">费用类型：</td>
						<td>
							<input style="width: 100%;" id="budgetitem" name="budgetitem" class="easyui-combobox" editable="false"
								data-options="
							    valueField: 'id',
							    textField: 'content',
							    url: '../budgetItemlist.do',
							    onSelect: function(rec){
							   		
							    },panelHeight: 'auto'">
						</td>
					</tr>
					<tr>
						<td style="width: 80px;">描述：</td>
						<td colspan="4">
							<input class="easyui-textbox" data-options="multiline:true" id="content" name="content"
								style="width: 100%; height: 70px;" />
						</td>
					</tr>
					<tr>
						<td style="width: 80px;">金额：</td>
						<td>
							<input class="easyui-textbox" data-options="validType:['number']" id="money" name="money"
								style="width: 100%;" />
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align: center;" id="div1">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">保存</a>
			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro = [[${capitalApply}]];

	$('#projectitemchild').combobox({width:$('#width1').width()}); 
	$(document).ready(function() {
		if(currentPro != null){
			$("#projectitem").combobox("setValue", currentPro.item);
			if (currentPro.projectitemchild != null){
				$("#projectitemchild").combobox("setValue", currentPro.projectitemchild);
			}
			$("#budgetitem").combobox("setValue", currentPro.budgetitem);
			$("#content").textbox("setValue", currentPro.content);
			$("#money").textbox("setValue", currentPro.money);
			if(currentPro.status != 6){
				document.getElementById('div1').style.display = 'none';
			}
		}else{
			currentPro = {};
		}
	});
	
	function savePro() {
		var projectitemid = $("#projectitem").combobox('getValue');
		currentPro.projectitemid = projectitemid;
		currentPro.projectitemchildid = $("#projectitemchild").combobox('getValue');
		var itemid = $("#budgetitem").combobox('getValue');
		currentPro.budgetitemid = itemid;
		var content = $("#content").textbox('getValue');
		currentPro.content = content;
		var money = $("#money").textbox('getValue');
		currentPro.money = money;
		if (!currentPro.status){
			currentPro.status = 6;
		}
		$.ajax({
			type : 'POST',
			url : "../capitalApplySave.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.alert('保存资金申请', '保存资金申请成功', 'success');
				}else{
					$.messager.alert('保存资金申请', '保存资金申请失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	$.extend($.fn.textbox.defaults.rules, {
		number : {//value值为文本框中的值
			validator : function(value) {
				var reg = /^\d+(\.\d+)?$/;
				return reg.test(value);
			},
			message : "请输入数字"
		},
		chinese : {
			validator : function(value,param) {
				var reg = /^[\u4e00-\u9fa5]+$/i;
				return reg.test(value);
			},
			message : "请输入中文"
		},
		checkLength : {
			validator : function(value,param) {
				return param[0] >= get_length(value);
			},
			message : '请输入最大{0}位字符'
		},
		specialCharacter : {
			validator : function(value,param) {
				var reg = new RegExp("[`~!@#$^&*()=|{}':;'\\[\\]<>~！@#￥……&*（）——|{}【】‘；：”“'、？]");
				return !reg.test(value);
			},
			message : '不允许输入特殊字符'
		},
		end : {
			validator : function(value,param) {
				var startDate = $("#startdate").val();
				var startTmp = new Date(startDate.replace(/-/g, "/"));
				var endTmp = new Date(value.replace(/-/g, "/"));
				return startTmp <= endTmp;
			},
			message : '结束时间不能早于开始时间！'
		},
		percent : {
			validator : function(value,param) {
				var percent = $("#remainpercent").text();
				return parseFloat(value) <= parseFloat(percent);
			},
			message : '不能超过剩余百分比'
		}
	});
</script>

</html>